<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{

	private $_acl = null;

/**
 * Function: _initAutoload
 * This helps to jump starts all the resources within the application
 * @return
 */
protected function _initAutoload()
{
		$moduleLoader = new Zend_Application_Module_Autoloader(array(
		'namespace' => '',
		'basePath' => APPLICATION_PATH . '/modules/default'));

		$this->_acl = new Model_acl;
		$this->_auth = Zend_Auth::getInstance();
	//Now get an instance of the Front Controller for use with registering plugins

	//If an Identity is present
	if (Zend_Auth::getInstance()->hasIdentity()){

		Zend_Registry::set('role', Zend_Auth::getInstance()->getStorage()->read()->role);
	}
	else {
		Zend_Registry::set('role', 'guest');
	}
	$fc = Zend_Controller_Front::getInstance();
	$fc->registerPlugin(new Plugin_AccessCheck($this->_acl));
		return $moduleLoader;


}

/**
 * Function: initViewHelper
 * This helps to initialize the layout object and return views with their corresponding actions
 * @return view object
 */
protected function _initViewHelpers(){

	$this->bootstrap('layout'); 	// Ensures that the layout object has been initialized
	$layout = $this->getResource('layout'); //Gets the layout resource
	$view = $layout->getView();
	$view->setHelperPath(APPLICATION_PATH .'/helpers');

	Zend_Dojo::enableView($view);
	$view->doctype('XHTML1_STRICT');
	$view->headMeta()->appendHttpEquiv('Content-Type', 'text/html;charset=utf-8');
	$view->headTitle('Grade-O-Meter');
	$view->headTitle()->setSeparator('-');

	//$view->setHelperPath(APPLICATION_PATH . '/helpers');

	//Setting up the site navigation
		$config = new Zend_Config_Xml(APPLICATION_PATH . '/configs/navigation.xml', 'nav');

		$navigation = new Zend_Navigation($config);
		$view->navigation($navigation)->setAcl($this->_acl)->setRole(Zend_Registry::get('role'));
}

/*
 * Function: setLocale
 * This sets the application's Locale
 */
 protected function _initLocale() {

	$locale = new Zend_Locale('en_US' );
	Zend_Registry::set('Zend_Locale', $locale);
 }


}

